<%-- 
    Document   : formAjoutPromo
    Created on : 23 mars 2013, 08:02:37
    Author     : ali
--%>



<%@page import="org.apache.jasper.tagplugins.jstl.core.Remove"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.HashMap"%>
<%@page import="EDT.obj.Formation"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.DateFormat"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                
        <title>Créer une promotion</title>
            <link rel="stylesheet" href="Accueil.css" />
            <link rel="SHORTCUT ICON" href="./edt.jpg" />
            
            <style type="text/css"> 
		
			dl.defs{ margin: 10px 0 10px 40px; }
			dl.defs dt{ font-weight: bold; line-height: 20px; margin: 10px 0 0 0; }
			dl.defs dd{ margin: -20px 0 10px 160px; padding-bottom: 10px; border-bottom: solid 1px #eee;}

			.wrapper{ background-color: #ffffff; width: 800px; border: solid 1px #eeeeee; padding: 20px; margin: 0 auto; }
			#tabs{ margin: 20px -20px; border: none; }
			#tabs, #ui-datepicker-div, .ui-datepicker{ font-size: 85%; }
			.clear{ clear: both; }

            </style> 
		
		<link rel="stylesheet" media="all" type="text/css" href="http://code.jquery.com/ui/1.10.0/themes/smoothness/jquery-ui.css" />
		<link rel="stylesheet" media="all" type="text/css" href="jquery-ui-timepicker-addon.css" />
		
		<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
		<script type="text/javascript" src="http://code.jquery.com/ui/1.10.0/jquery-ui.min.js"></script>
		<script type="text/javascript" src="jquery-ui-timepicker-addon.js"></script>
		<script type="text/javascript" src="jquery-ui-sliderAccess.js"></script>
		<script type="text/javascript">
			
			$(function(){
				$('#tabs').tabs();
		
				$('.example-container > pre').each(function(i){
					eval($(this).text());
				});
			});
		</script>
            
            <script language="JavaScript">

                <%
                ArrayList<Formation> formation = new ArrayList<Formation>();
    
                formation = (ArrayList<Formation> ) session.getAttribute("formation");
                int idf = Integer.parseInt(request.getParameter("formation"));
                
                String jscript="";
 
                    
                for (Formation f : formation)
                if (f.getId() == idf)
                for (int i =1; i<=f.getPeriodes();i++){
      
jscript+="      $(document).ready(function () {  ";                    
jscript+=" var startDateTextBox = $('#periode"+i+"_start');";
jscript+=" var endDateTextBox = $('#periode"+i+"_end');";

jscript+=" startDateTextBox.datepicker({ ";
jscript+="      dateFormat: 'dd/mm/yy',";
jscript+="      constrainInput: true,";

jscript+="	minDate: new Date(document.getElementsByName('anneeMin')[0].value),";
jscript+="	maxDate: new Date(parseInt(document.getElementsByName('annee')[0].value)+1,07,31),";

jscript+="	onClose: function(dateText, inst) { ";
jscript+="		if (endDateTextBox.val() != '') {";
jscript+="			var testStartDate = startDateTextBox.datetimepicker('getDate');";
jscript+="			var testEndDate = endDateTextBox.datetimepicker('getDate');";
jscript+="			if (testStartDate > testEndDate)";
jscript+="				endDateTextBox.datetimepicker('setDate', testStartDate);";
jscript+="		}";
jscript+="		else {";
jscript+="			endDateTextBox.val(dateText);";
jscript+="		}";
jscript+="	},";
jscript+="	onSelect: function (selectedDateTime){";
jscript+="		endDateTextBox.datetimepicker('option', 'minDate', startDateTextBox.datetimepicker('getDate') );";
jscript+="	}";
jscript+="});";


jscript+=" endDateTextBox.datepicker({ ";
jscript+="      dateFormat: 'dd/mm/yy',";
jscript+="      constrainInput: true,";

jscript+="	minDate: new Date(document.getElementsByName('anneeMin')[0].value),";
jscript+="	maxDate: new Date(parseInt(document.getElementsByName('annee')[0].value)+1,07,31),";

jscript+="	onClose: function(dateText, inst) {";
jscript+="		if (startDateTextBox.val() != '') {";
jscript+="			var testStartDate = startDateTextBox.datetimepicker('getDate');";
jscript+="			var testEndDate = endDateTextBox.datetimepicker('getDate');";
jscript+= "			if (testStartDate > testEndDate)";
jscript+="			startDateTextBox.datetimepicker('setDate', testEndDate);";
jscript+="		}";
jscript+="		else {";
jscript+="			startDateTextBox.val(dateText);";
jscript+="		}";
jscript+="	},";
jscript+="	onSelect: function (selectedDateTime){";
jscript+="		startDateTextBox.datetimepicker('option', 'maxDate', endDateTextBox.datetimepicker('getDate') );";
                        
jscript+="	}";
jscript+="});";
jscript+= "            });";
            

        }
                
                
                
                out.println(jscript);
                %>
   
         </script>
            
            
            
    </head>


    <body>    
         
    <section>
      

        

        
         
    <!--<form method='POST' action='PromoNivGradForm.do'> -->
   <%
     String form ="";
           
        form += "<form method='POST' action='AjoutPromoAct.do' target='section'>";
        form += "<div class='commentaire'>";
        form += "<fieldset>";
        
        
        form += "<input type='hidden' name='anneeMin' value='"+request.getParameter("annee")+",09,01'/>";
        
        
        form +="<legend>    Précisez les intervalles de temps des periodes :   </legend>";
        
        
        form += "<input type='hidden' name='formation' value='"+idf+"'/>"; 
        
        form += "<input type='hidden' name='key' value='"+session.getAttribute("key")+"'/>";
        
        
        for (Formation f : formation)
            if (f.getId() == idf){
                for (int i =1; i<=f.getPeriodes();i++){
                    
                form += "periode "+i+" :";
                form += "<div class='example-container'>"; 
            
                form += "Début : <input name='periodestart' id='periode"+i+"_start' value='' type='text'><br/>"; 
                form += "Fin   : <input name='periodeend' id='periode"+i+"_end' value='' type='text'>";
            
                form += "</div><br/>";
                }
                
                form += "<input type='hidden' name='nbrperiode' value='"+f.getPeriodes()+"'/>";
                               
            }
                
        form +="<input type='hidden' name='annee' value='"+request.getParameter("annee")+"'/>";
        
        form +="<input type='hidden' name='grp' value='"+request.getParameter("grp")+"'/>";
        
        form +="<input type='submit' value='valider'/><br/>";
        
        out.println(form);
        
        //session.removeAttribute("formation");
            
    %>
    
   
    
    
    <html:errors/> 
    
    </fieldset>
    
        
    </div>

    </form>
         
    </section>
    </body>
</html>